class_name ViewPosition extends Node2D

@onready var camera : Camera2D = $Camera2D
##持有这个组件的单位
@export var owner_unit : Unit
##组件类型
@export var component_type_list : Array[Enums.COMPONENT_TYPE] = [Enums.COMPONENT_TYPE.CAMERA]
@export var attributes : Attribute

var view_following_mouse :bool = true

func _unit_ready():
	camera.zoom = Vector2(2, 2)
	if !attributes:
		attributes = owner_unit.get_first_component_by_type(Enums.COMPONENT_TYPE.ATTRIBUTE)

func _process(delta):
	process_view_follow(delta)

func process_view_follow(delta):
	if view_following_mouse:
		var view_size = 0.2 + attributes.view_size
		var target_position = (get_global_mouse_position() - owner_unit.global_position) * view_size
		target_position.x = target_position.x * owner_unit.body_position.scale.x
		position = target_position
